import {BASE_URL, TIMEOUT} from './config'
import axios from "axios";

class HyRequest {
    constructor(baseURL, timeout) {
        this.instance = axios.create({baseURL, timeout})
        this.instance.interceptors.response.use(res => {
            if (res.status === 200) {
                return res.data;
            }
            console.error(res)
        }, err => {
            console.error(err)
        })
    }

    request(config) {
        return this.instance.request(config)
    }

    get(config) {
        return this.instance.request({...config, method: 'GET'})
    }

    post(config) {
        return this.instance.request({...config, method: 'POST'})
    }
}

const hyRequest = new HyRequest(BASE_URL, TIMEOUT)
export default hyRequest